package com.zhijiang.config.scheduled;//package com.zhijiang.config.scheduled;
//
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.toolkit.IdWorker;
//import com.zhijiang.hospital.entity.Checkin;
//import com.zhijiang.hospital.service.CheckinService;
//import com.zhijiang.hospital.service.SignSerivice;
//import com.zhijiang.util.HttpUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//
///**
// * 定时任务的使用
// * @author fan
// **/
//@Component
//@EnableScheduling
//@Slf4j
//public class Task  {
//
//    @Autowired
//    SignSerivice signSerivice;
//
//    @Autowired
//    CheckinService checkinService;
//
//    public static void main(String[] args) throws IOException {
//String url = "http://172.22.156.34:8888/SPDadjustprice.asmx";
//     //   String url ="http://xxx.xxx.xxx.xxx:xxx/cwbase/jtgl/ys/YuSuanService.asmx";
//        URL wsUrl = new URL(url);
//        HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
//        conn.setDoInput(true);
//        conn.setDoOutput(true);
//        conn.setRequestMethod("POST");
//        conn.setConnectTimeout(5*1000);
//        conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
//        conn.setRequestProperty("Content-Length", "length");
//        conn.setRequestProperty("SOAPAction", "http://tempuri.org/YuSuanQuery");
//        String req ="<?xml version=\"1.0\" encoding=\"utf-8\"?>";
//        req+="<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
//        req+="<soap:Body>";
//        req+="<YuSuanQuery xmlns=\"http://tempuri.org/\">";
//        req+="<query>";
//        req+="<USER>jkcs</USER>";
//        req+="<HSZZBH>00010503</HSZZBH>";
//        req+="<YSQJ>202203</YSQJ>";
//        req+="<SJLB>0201</SJLB>";
//        req+="<HSXMBH>660100030027</HSXMBH>";
//        req+="<FYXMBH>660100030027</FYXMBH>";
//        req+="</query>";
//        req+="</YuSuanQuery>";
//        req+="</soap:Body>";
//        req+="</soap:Envelope>";
//        OutputStream os = conn.getOutputStream();
//        os.write(req.getBytes());
////        OutputStreamWriter os = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
////        os.write(String.valueOf(req.getBytes()));
//        InputStream is = conn.getInputStream();
//        byte[] b = new byte[1024];
//        int len = 0;
//        String s = "";
//        while((len = is.read(b)) != -1){
//            String ss = new String(b,0,len,"UTF-8");
//            s += ss;
//        }
//        is.close();
//        os.close();
//        conn.disconnect();
//        System.out.println("服务器返回数据:"+s);
//
//    }
//
//    @Scheduled(cron="* 0/5 *  * * ? ")   //每5秒执行一次
//    public void execute() throws ParseException {
//        HashMap<String, String> maps = new HashMap<>();
//        String rq = HttpUtil.GetToken + "?Corpid=" + HttpUtil.Corpid + "&Corpsecret=" + HttpUtil.Corpsecret;
//        JSONObject gettokenRs = JSONObject.parseObject(HttpUtil.doGet(rq));
//
//        String token = gettokenRs.getString("access_token");//获取token
//
//        JSONObject body = new JSONObject();
//        List<String> idList = new ArrayList<>();
//        //获取所有人员信息
//        JSONObject getuserlistRs = JSONObject.parseObject(HttpUtil.doGet(HttpUtil.GetUserlist+ "?access_token=" + token+"&department_id=1&fetch_child=1"));
//        JSONArray userlist = getuserlistRs.getJSONArray("userlist");
//        final int ulsize = userlist.size();
//        for (int i = 0; i < ulsize; i++) {
//            JSONObject udata = userlist.getJSONObject(i);
//            String depuserId = udata.getString("userid");
//            maps.put(depuserId,udata.getString("name"));
//            idList.add(depuserId);
//        }
//        //时间
//        Date a = new Date();
//        a.setHours(0);
//        a.setMinutes(0);
//        a.setSeconds(0);
//        Date a1 = new Date();
//        a1.setHours(23);
//        a1.setMinutes(59);
//        a1.setSeconds(59);
//        //每100人为1组取数据
//        final int idlsize = idList.size();
//        for (int j = 0 ; j < idlsize; j+= HttpUtil.MAX_NUM) {
//
//            List<String> useridlist = idList.subList(j, j+HttpUtil.MAX_NUM>idList.size()?idList.size():j+HttpUtil.MAX_NUM);
//            body.put("opencheckindatatype", "3");
////            Calendar calendar = Calendar.getInstance();
////            calendar.set(Calendar.HOUR_OF_DAY, 0);
////            calendar.set(Calendar.MINUTE, 0);
////            calendar.set(Calendar.SECOND, 0);
////            calendar.add(Calendar.DATE, -1);
//            body.put("starttime", a.getTime()/ 1000);
//          //x  calendar.add(Calendar.DATE, 2);
//            body.put("endtime", a1.getTime() / 1000);
//            body.put("useridlist", useridlist);
//            JSONObject checkobj = JSONObject.parseObject(HttpUtil.doPost(HttpUtil.GetCheckindata + "?access_token=" + token, body));//取打卡数据
//            JSONArray checkindata = checkobj.getJSONArray("checkindata");
//            final int ckdsize = checkindata.size();
//            for (int i = 0; i < ckdsize; i++) {
//                Checkin checkin = new Checkin();
//                checkin.setCode(IdWorker.getTimeId());
//                JSONObject data = checkindata.getJSONObject(i);
//                checkin.setUserid(data.getString("userid"));
//               checkin.setType(data.getString("checkin_type"));
//                checkin.setLocaltionDetail(data.getString("location_detail"));
//                checkin.setLat(data.getString("lat"));
//                checkin.setLng(data.getString("lng"));
//                Long ckTime = data.getLong("checkin_time");//打卡时间毫秒数
//                checkin.setName(maps.get(data.getString("userid")));
//                SimpleDateFormat sfp = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
//                checkin.setCheckinTime(sfp.format(new Date(ckTime*1000)));
//               checkin.setLocaltionTitle(data.getString("location_title"));
//
//               checkin.setStarttime(a.toString());
//                checkin.setEndtime(a1.toString());
//                checkinService.add(checkin);
//
//            }
//        }
//
//    }
//
//
//
//}
